<div class="row">
     <div class="col-xs-12 col-xs-12">
          <div class="widget radius-bordered">
              <div class="widget-header bg-blue">
				<i class="widget-icon fa fa-arrow-down"></i>
				<span class="widget-caption">任务单编辑</span>
				<div class="widget-buttons">
					<a href="#" data-toggle="maximize">
						<i class="fa fa-expand"></i>
					</a>
					<a href="#" data-toggle="collapse">
						<i class="fa fa-minus"></i>
					</a>
					<a href="#" data-toggle="dispose">
						<i class="fa fa-times"></i>
					</a>
				</div>
			</div>
              <div class="widget-body">
                <form id="YstechForm" action="" method="post" class="form-horizontal"
                                                  data-bv-message=""
                                                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                                                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                                                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
                   <input type="hidden" name="taskid" value="{$cache.taskid}">
                   <div class="form-title">
                        <a href="{:U('Cms/Task/taskList',array('p'=>$p))}" class="btn btn-primary" data-loader="Ystech-loader" data-loadername="任务列表">
							             <i class="fa fa-mail-reply"></i>返回
						            </a>
                   </div>
                   <div class="form-group">
                        <label class="col-lg-2 control-label">任务主题<sup>*</sup></label>
                        <div class="col-lg-4">
                        <input type="text" name="subject" class="form-control" value="{$cache.subject}">
                        </div>
                    </div>
				            <div class="form-group">
                        <label class="col-lg-2 control-label">任务详情<sup>*</sup></label>
                        <div class="col-lg-4">
                        <input type="text" name="description" class="form-control" value="{$cache.description}">
                        </div>
                    </div>
                   <div class="form-group">
                        <label class="col-lg-2 control-label">负责人<sup>*</sup></label>
                        <div class="col-lg-4">
                            <select name="userid" class="selectpicker show-tick form-control">
                              <option value="0">--请选择--</option>
                              <volist name="users" id="use">
                                <option value="{$use['userid']}" <if condition="$use['userid'] eq $cache['userid']">selected</if>>{$use.username}</option>
                              </volist>
                            </select>
                        </div>
                    </div>  
                    <div class="form-group" >
                        <label class="col-lg-2 control-label">参与人(除负责人)</label>
                          <div class="col-lg-4">
                             <input type="hidden" id="partid" name="partid" value="">
                             <input type="text" id="input_part" name="followname" value="" class="form-control" placeholder="请输入参与者姓名,多个用'/'隔开">

                             
                          </div>
                           <button href="#" class="btn btn-primary" id="senduser">
                             <i class="fa fa-search"></i>搜索
                           </button>
                     </div> 
                     
                     <div class="form-group" id="notice">
                        <label class="col-lg-2 control-label"></label>
                          <div class="col-lg-4" >
                             <table class="col-lg-4" id="follow" style="width: 516px; padding: 50px;">
                             <volist name="parts" id="part">
                                <tr>
                                  <td><input name="checkvalue[]" type="checkbox"  style="opacity: inherit;position: inherit"  value="{$part.userid}" checked>{$part.username}</td>
                                </tr>
                             </volist>
                             </table>
                            <!-- <td><input name="checkvalue" type="checkbox"  style="opacity: inherit;position: inherit"  value="111">111</td>-->
                          </div>
                    </div>
                     
                     <div class="form-group" id="search" style="display: none">
                        <label class="col-lg-2 control-label">搜索结果</label>
                          <div class="col-lg-4" >
                             <table class="col-lg-4" id="t_search" style="width: 516px; padding: 50px;">
                             </table>
                            <!-- <td><input name="checkvalue" type="checkbox"  style="opacity: inherit;position: inherit"  value="111">111</td>-->
                          </div>
                     </div> 
                     <div class="form-group">
                        <label class="col-lg-2 control-label">客户<sup>*</sup></label>
                        <div class="col-lg-4"> 
                          <select name="clientid" class="selectpicker show-tick form-control">
                               <option value="0">--请选择--</option>
                               <volist name="clients" id="cl">
                                     <option value='{$cl.clientid}' <if condition="$cl['clientid'] eq $cache['clientid']">selected</if>>{$cl.cname}</option>
                               </volist>
                          </select>
                        </div> 
                      </div>  
                      <div class="form-group">
                        <label class="col-lg-2 control-label">指定车辆<sup>*</sup></label>
                        <div class="col-lg-4">
                        <select name="carid" class="form-control input-sm">
                                  <option value="0">--请选择--</option>
                                  <volist name="cars" id="car">
                                     <option value='{$car.carid}' <if condition="$car['carid'] eq $cache['carid']">selected</if>>{$car.carnum}</option>
                                  </volist>
                        </select> 
                        
                        </div> 
                    </div> 
				            <div class="form-group">
                        <label class="col-lg-2 control-label">起点<sup>*</sup></label>
                        <div class="col-lg-4">
                        <input type="text" name="init_add" class="form-control" value="{$cache.init_add}">
                        </div>
                    </div> 
				           <div class="form-group">
                        <label class="col-lg-2 control-label">终点</label>
                        <div class="col-lg-4">
                        <input type="text" name="destination" class="form-control" value="{$cache.destination}">
                        </div>
                   </div>
                   <div class="form-group">
                        <label class="col-lg-2 control-label">费用<sup>*</sup></label>
                        <div class="col-lg-4">
                        <input type="text" name="money" class="form-control" value="{$cache.money}">
                        </div>
                   </div>
                   <div class="form-group">
                        <label class="col-lg-2 control-label">任务开始时间<sup>*</sup></label>
                        <div class="col-lg-4">
                        <input type="text" name="begin" class="form-control" value="{$cache.begin}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-2 control-label">任务结束时间<sup>*</sup></label>
                        <div class="col-lg-4">
                        <input type="text" name="end" class="form-control" value="{$cache.end}">
                        </div>
                    </div>
                     <div class="form-group">
                        <label class="col-lg-2 control-label">状态</label>
                        <div class="col-lg-4">
                          <select name="status" class="form-control input-sm">
                                   <option value='0' <if condition="$cache.status eq 0">selected</if>>待完成</option>
                                   <option value='1' <if condition="$cache.status eq 1">selected</if>>完成</option>
                                   <option value='2' <if condition="$cache.status eq 2">selected</if>>执行中</option>
                          </select>
                        </div>
                   </div>

                   
					          <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                             <button class="btn btn-primary btn-lg" type="submit">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;
                             <button class="btn btn-palegreen btn-lg" type="reset">重填</button>
                        </div>
                    </div>
                 </form>

                </div>
        </div>
	</div>
     
</div>
<!--面包屑导航封装-->
<div id="tmpbread" style="display: none;">{$breadhtml}</div>
<script type="text/javascript">
	setBread($('#tmpbread').html());
</script>
<!--/面包屑导航封装-->
<!--  -->
<script type="text/javascript">
 
  $('#senduser').on('click',function(){
    var table = document.getElementById('t_search');
    var div_search = document.getElementById('search');
    var arr = chk();
    //console.log(arr);
    table.innerHTML='';
    var tourl="{:U('Cms/Task/followSet')}";
    var data = document.getElementById('input_part').value;
   

    $.post(tourl,{data:data,checked:arr},function(result){
           var div = document.getElementById('notice');
           var obj = JSON.parse(result);
            if(obj){
              div_search.setAttribute('style', 'display: block');
            }
            for(var i=0;i<obj.length;i++){
              var tr = document.createElement("tr");
              var td = document.createElement("td");
              var input = document.createElement("input");
              input.setAttribute('style', 'opacity: inherit;position: inherit');
              input.setAttribute('type', 'checkbox');
              input.setAttribute('name', 'checkvalue[]');
              table.appendChild(tr);
              tr.appendChild(td);
              td.appendChild(input);
              input.setAttribute('value', obj[i].userid);
              td.appendChild(document.createTextNode(obj[i].username+' '+obj[i].idnum));
              
            }

          
            //alert(typeof(obj));
            //for(var i=0;i<obj.length;i++){
             /* input.setAttribute('value', i.username);
              if(!isEmpty(i)){
                td.appendChild(input);
                tr.appendChild(td);
                table.appendChild(tr);
                tr.appendChild(td);
              }*/
              //console.log(i);
              
           // }
           /* if(obj.html){
              table.innerHTML = obj.html;
              div.setAttribute('style', 'display: block');
              $.Ystech.alert('danger', '请再次选择用户');
              return false;
            }*/
       });
  });




  function chk(){ 
    var obj=document.getElementsByName('checkvalue[]'); //取到对象数组后，我们来循环检测它是不是被选中 
    var s=''; 
   
    for(var i=0; i<obj.length; i++){ 
      if(obj[i].checked) s+=obj[i].value+','; //如果选中，将value添加到变量s中 
    } 
    return s; 
  } 

 function isEmpty(obj) {
    if (obj === null) return true;
    if (typeof obj === 'undefined') {
      return true;
    }
    if (typeof obj === 'string') {
      if (obj === "") {
        return true;
      }
      var reg = new RegExp("^([ ]+)|([　]+)$");
      return reg.test(obj);
    }
    return false;
  }  


</script>
<!--表单验证与提交封装-->
<script type="text/javascript">
	$('#YstechForm').bootstrapValidator({
		submitHandler: function (validator, form, submitButton) {
			var lid='';
			var checks=$('.label-check');
			$(checks).each(function(){
				if($(this).is(":checked")){
					lid+=$(this).val()+',';
				}
			});
			$('#lid').val(lid);
			
			if($('input[name="subject"]').val() == 0){
				$.Ystech.alert('danger','请填写任务主题！');
				return false;
			}
      console.log($('select[name="userid"]').val());
			
			if($('select[name="userid"]').val() == 0){
        
				$.Ystech.alert('danger','请选择负责人！');
				return false;
			}
			
			if($('select[name="carid"]').val() == 0){
				$.Ystech.alert('danger','请选择车辆！');
				return false;
			}
      
      var tourl="{:U('Cms/Task/taskSet')}";
			var data=$('#YstechForm').serialize();
      //console.log(tourl);
      //console.log(data);
     $.Ystech.ajax('post',tourl,data,null);
			return false;
        },
	});

  $('#isfxbtn').on('click',function(){
		var value=$(this).prop('checked')?1:0;
		$('#isfx').val(value);
	});
	
	$('#isjxbtn').on('click',function(){
		var value=$(this).prop('checked')?1:0;
		$('#isjx').val(value);
	});
	
</script>
<!--/表单验证与提交封装-->

